package com.jt.tenant.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.jt.tenant.R;
import com.jt.tenant.adapter.SpecialSaleListAdapter;
import com.jt.tenant.app.JTApplication;
import com.jt.tenant.conn.GetGSOrderId;
import com.jt.tenant.conn.GetGasStationList;
import com.jt.tenant.conn.GetSpecialSaleList;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilToast;

import java.util.ArrayList;
import java.util.List;

public class SpecialSaleActivity extends JTActivity implements OnClickListener {

    private TextView title;

    private ListView listView;

    private ImageView iv_special_sale;

    private List<GetSpecialSaleList.SSList> mList = new ArrayList<>();

    private SpecialSaleListAdapter mAdapter;

    private GetSpecialSaleList getSpecialSaleList;

    private String ss_id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_special_sale);

        ss_id = getIntent().getStringExtra("id");

        initView();

    }

    @Override
    protected void onResume() {

        super.onResume();

        getSpecialSaleList.id = ss_id;

        getSpecialSaleList.execute(this);

    }

    private void initView() {

        (title = (TextView)findViewById(R.id.tv_title_name)).setText("专场");

        iv_special_sale = (ImageView)findViewById(R.id.iv_special_sale);

        listView = (ListView)findViewById(R.id.lv_special_sale);

        mAdapter = new SpecialSaleListAdapter(this,mList);

        listView.setAdapter(mAdapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {

                Intent intent = new Intent(context,MaintainShopActivity.class);

                Bundle bundle = new Bundle();

                bundle.putString("id",mList.get(position).ID);

                intent.putExtras(bundle);

                startActivity(intent);

            }
        });

        getSpecialSaleList = new GetSpecialSaleList(new AsyCallBack<GetSpecialSaleList.Info>(){
            @Override
            public void onSuccess(String toast, int type, GetSpecialSaleList.Info info) throws Exception {

                super.onSuccess(toast, type,info);

                mList.clear();

                mList.addAll(info.ssLists);

                mAdapter.notifyDataSetChanged();

                JTApplication.UtilAsyncBitmap.get(info.logourl, iv_special_sale, R.mipmap.loading);

            }

            @Override
            public void onFail(String toast, int type) throws Exception {
                super.onFail(toast, type);
            }

            @Override
            public void onEnd(String toast, int type) throws Exception {
                super.onEnd(toast, type);
                if(!toast.equals("")){

                    UtilToast.show(SpecialSaleActivity.this, toast);

                }
            }
        });

    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {


        }

    }


}
